import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:moose_app/core/utils/focus_util.dart';
import 'package:moose_app/core/utils/navigate_util.dart';
import 'package:moose_app/ui/screens/back_choose/back_choose_screen.dart';
import 'package:moose_app/ui/screens/register/register_screen.dart';
import 'package:moose_app/ui/widgets/already_a_user.dart';
import 'package:moose_app/ui/widgets/auth/auth_account_input.dart';
import 'package:moose_app/ui/widgets/auth/auth_button.dart';
import 'package:moose_app/ui/widgets/auth/auth_password_input.dart';

import 'login_background.dart';

class ATHLoginBody extends StatefulWidget {
  ATHLoginBody({Key key}) : super(key: key);

  @override
  _LoginBodyState createState() => _LoginBodyState();
}

class _LoginBodyState extends State<ATHLoginBody> {
  final TextEditingController _usernameController = TextEditingController();
  final TextEditingController _passwordController = TextEditingController();

  @override
  void initState() {
    super.initState();
    _usernameController.text = "江景";
    _passwordController.text = "123";
  }

  void _onLoginButtonPressed() async {
    ATHNavigator.pushReplace(context, ATHBackChooseScreen.routeName,
        clearStack: true);
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
        onTap: () {
          ATHFocusUtil.requestFocus(context);
        },
        child: ATHLoginBackground(
          child: SingleChildScrollView(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Image.asset(
                  'assets/images/login.png',
                  height: 400.h,
                ),
                ATHAuthAccountInput(
                  hintText: "账号",
                  controller: _usernameController,
                  // onChanged: (value) => {print('$value')},
                ),
                ATHAuthPasswordInput(
                  hintText: "密码",
                  controller: _passwordController,
                  // onChanged: (value) => {},
                ),
                ATHAuthButton(
                  text: "登录",
                  press: () {
                    ATHFocusUtil.requestFocus(context);
                    _onLoginButtonPressed();
                  },
                ),
                ATHUserAlready(
                  login: true,
                  press: () {
                    ATHNavigator.pushReplace(
                        context, ATHRegisterScreen.routeName);
                  },
                ),
              ],
            ),
          ),
        ));
  }
}
